/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package merlion.scm.rmpm.entity;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Date;
import java.util.Random;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import javax.persistence.CascadeType;
import javax.persistence.FetchType;

/**
 *
 * @author Yuwei
 */
@Entity
public class RawMaterialItemLine implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    @OneToOne(targetEntity=RawMaterialSupplyInformation.class, cascade={CascadeType.PERSIST, CascadeType.MERGE}, fetch=FetchType.EAGER)
    private RawMaterialSupplyInformation rawMaterialSupplyInformation;
    private Long qty;
    private Double subtotalSGD;
    private Double subtotalUSD;
    private Timestamp hiddenId;
    
    public RawMaterialItemLine(){
        rawMaterialSupplyInformation = new RawMaterialSupplyInformation();
        qty = (long)0;
        subtotalSGD = (double)0;
        subtotalUSD = (double)0;
        
        Random rand = new Random();
        long seed = new Date().getTime() + (long)rand.nextInt(10000);
        hiddenId = new Timestamp(seed);
    }

    public Long getQty() {
        return qty;
    }

    public void setQty(Long qty) {
        this.qty = qty;
    }

    public RawMaterialSupplyInformation getRawMaterialSupplyInformation() {
        return rawMaterialSupplyInformation;
    }

    public void setRawMaterialSupplyInformation(RawMaterialSupplyInformation rawMaterialSupplyInformation) {
        this.rawMaterialSupplyInformation = rawMaterialSupplyInformation;
    }

    public Double getSubtotalSGD() {
        return subtotalSGD;
    }

    public void setSubtotalSGD(Double subtotalSGD) {
        this.subtotalSGD = subtotalSGD;
    }

    public Double getSubtotalUSD() {
        return subtotalUSD;
    }

    public void setSubtotalUSD(Double subtotalUSD) {
        this.subtotalUSD = subtotalUSD;
    }

    public Timestamp getHiddenId() {
        return hiddenId;
    }

    public void setHiddenId(Timestamp hiddenId) {
        this.hiddenId = hiddenId;
    }
    
    @Override
    public RawMaterialItemLine clone(){
        RawMaterialItemLine rmil = new RawMaterialItemLine();
        
        rmil.setQty(qty);
        rmil.setRawMaterialSupplyInformation(rawMaterialSupplyInformation);
        rmil.setSubtotalSGD(subtotalSGD);
        rmil.setSubtotalUSD(subtotalUSD);
        
        return rmil;
    }
    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof RawMaterialItemLine)) {
            return false;
        }
        RawMaterialItemLine other = (RawMaterialItemLine) object;
        // Compare hiddenId
        if(!this.hiddenId.equals(other.hiddenId))
            return false;
        return true;
    }

    @Override
    public String toString() {
        return "merlion.scm.rmpm.entity.RawMaterialItemLine[ id=" + id + " ]";
    }
    
}
